package com.ndf.learn.controller;

import com.ndf.learn.model.User;
import com.ndf.learn.service.IUserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by lin on 2017/11/19.
 */
@Controller
@RequestMapping(value = "/user")
public class UserController {

    @Resource
    private IUserService userService;

    @RequestMapping(value = "/list", method = {RequestMethod.GET,RequestMethod.POST})
    public String list(Integer limit, Integer pageSize, Model view){
        Map<String, Object> paramMap = new HashMap<String, Object>();
        if(limit == null){
            limit = 0;
        }
        if(pageSize == null){
            pageSize = 10;
        }
        paramMap.put("limit", limit);
        paramMap.put("pageSize", pageSize);

        List<User> userList = userService.queryList(paramMap);
        view.addAttribute("userList", userList);
        return "userList.vm";
    }

}
